package mvc.model;

import java.util.ArrayList;


import mvc.view.ViewCurve;

import org.geom.Point3D;
import org.geom.Vector3D;
import org.geom.curve.ICurve;

public abstract class ModelCurve implements ICurve, IModelCurve{
		
	protected ICurve curve;
	protected ArrayList<ViewCurve> views = new ArrayList<ViewCurve>();
	protected ArrayList<ModelCurve> parents = new ArrayList<ModelCurve>();
	public int arc;
	
	//---------------------------------------------------------------------- constructor
	public ModelCurve(ICurve curve) {
		this.curve = curve;
	}
	
	//---------------------------------------------------------------------- observable
	/* (non-Javadoc)
	 * @see mvc.IModel#addView(mvc.ViewCurve)
	 */
	public void addView(ViewCurve v) {
		views.add(v);
	}
	
	/* (non-Javadoc)
	 * @see mvc.IModel#notifyAllViews()
	 */
	public void notifyAllViews() {
		for (ViewCurve v : views) {
			v.updateFromModel();
			v.repaint();
		}
		
		for(ModelCurve p: parents) {
			p.notifyAllViews();
		}
	}
	
	public void addParent(ModelCurve parent) {
		parents.add(parent);
	}
	
	public void removeParent(ModelCurve parent) {
		parents.remove(parent);
	}
	
	//---------------------------------------------------------------------- ICurve delegation
	
	public ICurve getCurve() {
		return curve;
	}
	
	public ArrayList<Point3D> getPoints() {
		return curve.getPoints();
	}

	@Override
	public Vector3D binormal(float t) {
		return curve.binormal(t);
	}

	@Override
	public Vector3D normal(float t) {
		return curve.normal(t);
	}

	@Override
	public Point3D sample(float t) {
		return curve.sample(t);
	}

	@Override
	public Vector3D tangent(float t) {
		return curve.tangent(t);
	}
	

	@Override
	public void setCurrentPoint(float t) {
		curve.setCurrentPoint(t);
		notifyAllViews();
		
		for (ModelCurve p : parents) {
			p.setCurrentPoint(t);
		}
	}
	
	@Override
	public Point3D getCurrentPoint() {
		return curve.getCurrentPoint();
	}
	
	@Override 
	public float getCurrentT() {
		return curve.getCurrentT();
	}
	

	@Override
	public float getArc() {
		return curve.getArc();
	}

}
